import 'package:flutter_wan_android/core/storage/database_storage.dart';
import 'package:flutter_wan_android/data/article/article_network_api.dart';
import 'package:flutter_wan_android/data/article/article_repository.dart';
import 'package:flutter_wan_android/data/banner/banner_local_api.dart';
import 'package:flutter_wan_android/data/banner/banner_network_api.dart';
import 'package:flutter_wan_android/data/banner/banner_repository.dart';
import 'package:flutter_wan_android/data/user/user_local_api.dart';
import 'package:flutter_wan_android/data/user/user_network_api.dart';
import 'package:flutter_wan_android/data/user/user_repository.dart';
import 'package:provider/provider.dart';
import 'package:provider/single_child_widget.dart';

import '../http/network_module.dart';
import '../storage/kv_cache_storage.dart';

// provider 需要注意初始化顺序

List<SingleChildWidget> get sharedProviders {
  return [..._networkProviders, ..._localProviders, ..._repositoryProviders];
}

List<SingleChildWidget> _networkProviders = [
  Provider(create: (context) => NetworkModule(), lazy: false),
  Provider(create: (context) => UserNetworkApi(context.read<NetworkModule>())),
  Provider(create: (context) => BannerNetworkApi(context.read<NetworkModule>())),
  Provider(create: (context) => ArticleNetworkApi(context.read<NetworkModule>())),

];

List<SingleChildWidget> _localProviders = [
  Provider(create: (context) => KVCacheStorage()),
  Provider(create: (context) => DataBaseStorage()),
  Provider(
    create:
        (context) => UserLocalApi(
          context.read<DataBaseStorage>(),
          context.read<KVCacheStorage>(),
        ),
  ),
  Provider(create: (context) => BannerLocalApi(),)
];

List<SingleChildWidget> _repositoryProviders = [
  Provider(
    create:
        (context) => UserRepository(
          context.read<UserNetworkApi>(),
          context.read<UserLocalApi>(),
        ),
  ),
  Provider(
    create:
        (context) => BannerRepository(
          context.read<BannerNetworkApi>(),
          context.read<BannerLocalApi>(),
        ),
  ),
  Provider(
    create:
        (context) => ArticleRepository(
          context.read<ArticleNetworkApi>(),
        ),
  )
];
